package com.rock.code.bigdata.forecast.controller;


import com.github.pagehelper.PageInfo;
import com.rock.code.base.controller.BaseController;
import com.rock.code.bigdata.forecast.domain.TbSysForeCast;
import com.rock.code.bigdata.forecast.service.ForeCastService;
import com.rock.code.bigdata.targets.domain.TbSysTarget;
import com.rock.code.bigdata.targets.service.TbSysTargetService;
import com.rock.code.common.exceptions.SystemException;
import com.rock.code.common.pager.Page;
import org.codehaus.groovy.runtime.powerassert.SourceText;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author piandu
 * @description 性能预测
 * @date 2018/10/24
 */
@Controller
@RequestMapping("/Forecast")
public class ForeCastController extends BaseController {

    @RequestMapping("")
    public String queryForecastView() {
        return "bigdata/forecast/ForeCastView";
    }


    @Resource
    private ForeCastService ForeCastServiceImpl;

    /**
     * queryPageListForceCast
     * 预测指标展示
     *
     * @return the page info
     * @throws Exception the exception
     */
    @ResponseBody
    @RequestMapping(value = "/queryPageListForceCast", method = RequestMethod.POST)
    public PageInfo<TbSysForeCast> queryPageListForceCast() throws Exception {
        Map<String, Object> param = this.getRequestMapSingle();
        Page page = new Page(request);
        PageInfo pageInfo = null;
        try {
            pageInfo = ForeCastServiceImpl.queryPageListForceCast(page, param);
        } catch (Exception e) {
            e.printStackTrace();
            throw new SystemException(e);
        }
        return pageInfo;
    }


    //==============================================================================================================
    //趋势预测查询调用方法
    @ResponseBody
    @RequestMapping(value = "/forecastQuery", method = RequestMethod.POST)
    public HashMap forecastQuery(String EXT_UNIT_ID, String KPI_CODE) {
        HashMap map = new HashMap();
        HashMap resultMap = new HashMap();
        List list = new ArrayList();
        List listJx = new ArrayList();
        List listDrz = new ArrayList();
        try {
            if (EXT_UNIT_ID != null && KPI_CODE != null) {
                map.put("EXT_UNIT_ID", EXT_UNIT_ID);
                map.put("KPI_CODE", KPI_CODE);
            }
            /*******************************预测***********************************/
            String tableName = ForeCastServiceImpl.monthTableName();//预测值月表名
            map.put("tableName", "tb_kpitrend_value_day_201811");
            String forecastDay = ForeCastServiceImpl.forecastDate();//预测条件日（当天）
            map.put("forecastDay", "2018-12-01 00:00:00");
            list = ForeCastServiceImpl.forecastQuery(map);

            /*******************************基线***********************************/
            String tableNameJx = ForeCastServiceImpl.monthTableNameJx();//基线月表名
            map.put("tableNameJx", "tb_kpibaseline_value_201811");
            String baseLineDay = ForeCastServiceImpl.baseLineDate();//基线条件日（昨天）
            map.put("baseLineDay", "2018-12-01 00:00:00");
            listJx = ForeCastServiceImpl.queryJx(map);

            /*******************************当日值***********************************/
            String thevalueofDay = ForeCastServiceImpl.thevalueofDate();//当日值条件日（当天）
            map.put("thevalueofDay", thevalueofDay);
            listDrz = ForeCastServiceImpl.queryDrz(map);

            resultMap.put("list", list);
            resultMap.put("listJx", listJx);
            resultMap.put("listDrz", listDrz);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("产生了异常");
        }
        return resultMap;
    }

    //文件系统使用率
    @ResponseBody
    @RequestMapping(value = "/FileSystem", method = RequestMethod.POST)
    public HashMap FileSystem(String EXT_UNIT_ID, String KPI_CODE) {
        HashMap map = new HashMap();
        HashMap resultMap = new HashMap();
        List list = new ArrayList();
        List listJx = new ArrayList();
        List listDrz = new ArrayList();
        if (EXT_UNIT_ID != null && KPI_CODE != null) {
            map.put("EXT_UNIT_ID", EXT_UNIT_ID);
            map.put("KPI_CODE", KPI_CODE);
            String tableName = ForeCastServiceImpl.monthTableName();//预测值月表名
            map.put("tableName", tableName);
            String forecastDay = ForeCastServiceImpl.forecastDate();//预测条件日（当天）
            map.put("forecastDay", forecastDay);
            list = ForeCastServiceImpl.FileSystem(map);
        }
        if (EXT_UNIT_ID != null && KPI_CODE != null) {
            map.put("EXT_UNIT_ID", EXT_UNIT_ID);
            map.put("KPI_CODE", KPI_CODE);
            String tableNameJx = ForeCastServiceImpl.monthTableNameJx();//基线月表名
            map.put("tableNameJx", tableNameJx);
            String baseLineDay = ForeCastServiceImpl.baseLineDate();//基线条件日（昨天）
            map.put("baseLineDay", baseLineDay);
            listJx = ForeCastServiceImpl.FileSystemJx(map);
        }
        if (EXT_UNIT_ID != null && KPI_CODE != null) {
            map.put("EXT_UNIT_ID", EXT_UNIT_ID);
            map.put("KPI_CODE", KPI_CODE);
            String thevalueofDay = ForeCastServiceImpl.thevalueofDate();//当日值条件日（当天）
            map.put("thevalueofDay", thevalueofDay);
            listDrz = ForeCastServiceImpl.FileSystemDrz(map);
        }
        resultMap.put("list", list);
        resultMap.put("listJx", listJx);
        resultMap.put("listDrz", listDrz);
        return resultMap;
    }
}
